import React, { useEffect, useCallback, useState } from 'react';
import Learning from "@/component/layout/Learning/Learning";
import Advice from "@/component/layout/Advice/Advice";
import ListTitle from "@/component/layout/ListTitle/ListTitle";
import Loading from "@/component/layout/loading/loading";
import { getLastMeetingList, getFutureLast } from '@/network/protocol';
// import { advice1, learn1} from '@/mock/advice'


const img1 = <img className="lingdang" src={require('../../assests/img/lingdang.png')} alt="" />;
const img2 = <img className="maozi" src={require('../../assests/img/maozi.png')} alt="" />;


const Main = (props) => {
  const [learn, setLearn] = useState({})
  const [advice, setAdvice] = useState([])
  const [loading1, setLoading1] = useState(true);
  const [loading2, setLoading2] = useState(true);
  const getLearn = useCallback(async () => {
    try {//limitCount
      let res = await getLastMeetingList();
      if (res.errorCode === 0) {
        let item = { ...res.source }
        setLearn(item)
      }
      setLoading1(false)
    } catch (error) {
      setLoading1(false)
    }
  }, [])
  const getAdvice = useCallback(async () => {
    try {
      let res = await getFutureLast({ limitCount: 3 });
      if (res.errorCode === 0) {
        let item = res.source
        setAdvice(item)
      }
      setLoading2(false)
    } catch (error) {
      setLoading2(false)
    }

  }, [])
  useEffect(() => {
    getLearn()
    getAdvice()
  }, [getAdvice, getLearn])

  return (
    <div className="Main-box">
      <div className="Learning-box">
        <ListTitle img={img1} text={"最新的学术通知"} showstar />
        {loading1 ? <Loading style={{ height: '3rem' }} /> : <Learning data={learn} />}
      </div>

      <div className="Learning-box Learning-box1">
        <ListTitle img={img2} text={"宁视点"} showstar />
        {loading2 ?
          <Loading style={{ height: '3rem' }} /> :
          <>
            {
              advice.map((item, index) => {
                return < Advice data={item} key={item.id} to={'/ningGDetail?id='+item.id} />
              })
            }
          </>
        }

      </div>
    </div>
  )
}


export default React.memo(Main);